home *** CD-ROM | disk | FTP | other *** search
-
- ; ---------------------------------------------------------------------
- ; Simple example of double-buffered animation - support@blitzbasic.com
- ; ---------------------------------------------------------------------
-
- ; Note that anything after a ";" is a comment, and not part of the code!
- ; See "quick example uncommented.bb" for the raw code.
-
- ; ---------------------------------------------------------------------
- ; First, we open a display 640 pixels wide and 480 pixels high...
- ; ---------------------------------------------------------------------
-
- Graphics 640, 480
-
- ; ---------------------------------------------------------------------
- ; Now, we set up double-buffered animation, using the 'back buffer'
- ; ---------------------------------------------------------------------
-
- ; Telling Blitz to use the 'back buffer' means that all following draw
- ; commands will not be drawn immediately. They'll be drawn to a 'hidden'
- ; display, and only shown on screen once all drawing operations are
- ; complete, when we call the Flip command. This avoids a flickering
- ; display.
-
- SetBuffer BackBuffer ()
-
- ; ---------------------------------------------------------------------
- ; Load an image in the same directory as the source code...
- ; ---------------------------------------------------------------------
-
- ; Here we load an image called "rocket.bmp" and store it as a 'handle'
- ; called 'player'. We then use this handle in our drawing operations.
-
- ; The MaskImage line makes the area around the rocket transparent. This
- ; area has an RGB value of 255, 0, 255, which is bright pink (rarely
- ; used for anything). The background can be any colour -- just note
- ; the RGB values when you create it in your paint program, and use
- ; those instead.
-
- player = LoadImage ("rocket.bmp")
- MaskImage player, 255, 0, 255
-
- ; ---------------------------------------------------------------------
- ; Main game loop
- ; ---------------------------------------------------------------------
-
- ; We use a 'Repeat... Until' loop (see manual for an explanation if
- ; you're new to this) in our main loop. This means that everything in
- ; between will be repeated until, in this case, the player presses
- ; ESC (which has a key code of 1, seen in KeyHit here).
-
- Repeat
-
- ; -----------------------------------------------------------------
- ; First, we clear the display...
- ; -----------------------------------------------------------------
-
- Cls
-
- ; -----------------------------------------------------------------
- ; Then we draw the image...
- ; -----------------------------------------------------------------
-
- ; Remember we're drawing to a hidden display (the back buffer), so
- ; this doesn't appear until Flip is called... note that MouseX ()
- ; and MouseY () simply refer to the current mouse position.
-
- DrawImage player, MouseX (), MouseY () ; Draw the image
-
- ; -----------------------------------------------------------------
- ; Then we show the result on screen...
- ; -----------------------------------------------------------------
-
- Flip
-
- Until KeyHit (1)
-
- End ; Program exits here...
-